package com.lry.basic.algorithm.common;

/**
 * @author:刘仁有
 * @desc: 数组的最大上升子序列
 * @email:953506233@qq.com
 * @data:2019/9/5
 */
public class MaxUpSubArr {
    public static void main(String[] args) {
        System.out.println(maxUpSubArr(new int[]{-1,1,-3,3}));
        System.out.println(findLengthOfLCIS(new int[]{3,0,6,2,4,7,0,0}));
    }
    private static int maxUpSubArr(int[] arr){
        int[] dp = new int[arr.length];
        for(int i=0;i<arr.length;i++){
            dp[i] = 1;
            for(int j=0;j<i;j++){
                if(arr[i]>arr[j]){
                    dp[i] = Math.max(dp[i],dp[j]+1);
                }
            }
        }
        return maxInArr(dp);
    }

    private static int maxInArr(int[] dp) {
        int max = dp[0];
        for(int i=1;i<dp.length;i++){
            max = Math.max(max,dp[i]);
        }
        return max;
    }

    //最长且连续的的递增序列。
    //[1,3,5,4,7] 1 3 5
    private static int findLengthOfLCIS(int[] nums){
        if(null==nums||nums.length==0)
            return 0;
        int alreadyMax=0;
        int max=1;
        for(int i=1;i<nums.length;i++){
            if(nums[i]>nums[i-1]){
                max++;
            }else{
                if(max>alreadyMax)
                alreadyMax = max;
                max=1;
            }
        }
        return Math.max(max,alreadyMax);
    }
}
